﻿using Learun.Util;
using log4net.Config;
using System;
using System.Collections.Generic;

namespace Learun.Application.TwoDevelopment.ZZDT_EC
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创 建：超级管理员
    /// 日 期：2022-03-07 13:45
    /// 描 述：工程数据图元
    /// </summary>
    public class ec_enginedata_pixelBLL : ec_enginedata_pixelIBLL
    {
        private ec_enginedata_pixelService ec_enginedata_pixelService = new ec_enginedata_pixelService();

        #region 获取数据
        /// <summary>
        /// 清理无效的pixel（句柄对应的文件、位号不存在时）
        /// </summary>
        /// <param name="drawingFileID"></param>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        public bool Clear(string drawingFileID, string ProjectId)
        {
            try
            {
                return ec_enginedata_pixelService.Clear(drawingFileID, ProjectId);
            }
            catch (Exception ex)
            {
                XmlConfigurator.Configure();
                var log = log4net.LogManager.GetLogger("ERROR"); //参数就是config里logger节点的名字
                log.Error($"★★★{DateTime.Now.ToString()}★★★ec_enginedata_pixelBLL.cs 中 Clear方法，去清理无效的pixel对象时【{ex.Message}】★★★");
                return true;
            }
        }

        /// <summary>
        /// 获取列表数据
        /// <summary>
        /// <returns></returns>
        public IEnumerable<ec_enginedata_pixelEntity> GetList(string queryJson)
        {
            try
            {
                return ec_enginedata_pixelService.GetList(queryJson);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        /// <summary>
        /// 获取工程数据图元表数据
        /// <summary>
        /// <param name="EngineDataID">工程数据ID</param>
        /// <param name="ProjectId">项目ID</param>
        /// <returns></returns>
        public IEnumerable<ec_enginedata_pixelEntity> GetEnginePixelById(string ProjectId, string EngineDataID)
        {
            try
            {
                return ec_enginedata_pixelService.GetEnginePixelById(ProjectId, EngineDataID);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
        /// <summary>
        /// 获取图纸工程数据
        /// <summary>
        /// <returns></returns>
        public IEnumerable<ec_enginedata_pixelEntity> GetDrawingEnginePixel(string queryJson)
        {
            try
            {
                return ec_enginedata_pixelService.GetDrawingEnginePixel(queryJson);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
        #endregion

        #region 提交数据

        /// <summary>
        /// 图元（Web）
        /// <param name="engineDataID">工程数据ID</param>
        /// <summary>
        /// <returns></returns>
        public void SavePixelsWeb(string engineDataID, List<ec_enginedata_pixelEntity> entityList, string ProjectId)
        {
            try
            {
                ec_enginedata_pixelService.SaveEnginePixel(engineDataID, entityList, ProjectId);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }



        /// <summary>
        /// 批量保存工程数据图元（插件端）
        /// <summary>
        /// <returns></returns>
        public void SavePixels(List<ec_enginedata_pixelEntity> entityList, string ProjectId, string drawingFileID)
        {
            try
            {
                new ec_enginedata_pixelService().SavePixels(entityList, ProjectId, drawingFileID);


            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }

        #endregion

    }
}
